#include "GY_GraphicsRectWidthHeight.h"
 
GY_GraphicsRectWidthHeight::GY_GraphicsRectWidthHeight(const QString &guid, QGraphicsItem *parent)
    :GY_BasicsGraphicsObject(guid,this,parent)
{
    initializationPropertyInfo();
    //向map中存入数据
    QPointF Position=m_PropertyInfoMap.value("Position").propertyValue.value<QPointF>();//位置变化点
    QPointF pointTran=m_PropertyInfoMap.value("pointTran").propertyValue.value<QPointF>();//形状变化点
    QPointF point1=m_PropertyInfoMap.value("point1").propertyValue.value<QPointF>();//位置变化点
    QPointF point2=m_PropertyInfoMap.value("point2").propertyValue.value<QPointF>();//形状变化点
    QPointF point3=m_PropertyInfoMap.value("point3").propertyValue.value<QPointF>();//位置变化点
    QPointF point4=m_PropertyInfoMap.value("point4").propertyValue.value<QPointF>();//形状变化点
    qreal width=m_PropertyInfoMap.value("Width").propertyValue.value<double>();//矩形宽度
    qreal height=m_PropertyInfoMap.value("Height").propertyValue.value<double>();//矩形高度

    updatePath(Position,pointTran,QPointF(Position.x()+width,Position.y()),QPointF(Position.x(),Position.y()+height));
    //初始化map，并向map中存入标签和数据
    QMap<QVariant,QPointF> editPoints = {{"pointTran",pointTran},
                                         {"point1",point1},{"point2",point2},
                                         {"point3",point3},{"point4",point4}};

    //对map进行操作
    this->setEditPointF(editPoints);  
    this->setCenterPointF(m_PropertyInfoMap["Position"].propertyValue.toPointF());
    //设置point颜色
//    this->setPen(QColor(Qt::red));
}

GY_GraphicsRectWidthHeight::GY_GraphicsRectWidthHeight(const QString &guid,
                                                       qreal x,qreal y,qreal width, qreal height,
                                                       QGraphicsItem *parent)
    :GY_BasicsGraphicsObject(guid,this,parent)
{
    initializationPropertyInfo();
    QPointF Position=QPointF(x,y);

    m_PropertyInfoMap["Position"].propertyValue=Position;//更新数据后插入map中（下同）

    QPointF pointTran=QPointF(x+width,y+height);//形状变化点
    m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

    QPointF point1=QPointF(x,y+height/2);//位置变化点
    m_PropertyInfoMap["point1"].propertyValue=point1;

    QPointF point2=QPointF(x+width,y+height/2);//形状变化点
    m_PropertyInfoMap["point2"].propertyValue=point2;

    QPointF point3=QPointF(x+width/2,y+height);//位置变化点
    m_PropertyInfoMap["point3"].propertyValue=point3;

    QPointF point4=QPointF(x+width/2,y);//形状变化点
    m_PropertyInfoMap["point4"].propertyValue=point4;

    m_PropertyInfoMap["Width"].propertyValue=width;
    m_PropertyInfoMap["Height"].propertyValue=height;
    //生成矩形
    updatePath(Position,pointTran,QPointF(Position.x()+width,Position.y()),QPointF(Position.x(),Position.y()+height));
    QMap<QVariant,QPointF> editPoints = {{"pointTran",pointTran},
                                         {"point1",point1},{"point2",point2},
                                         {"point3",point3},{"point4",point4}};
    this->setEditPointF(editPoints);
//    this->setPen(QColor(Qt::red));
    this->setCenterPointF(m_PropertyInfoMap["Position"].propertyValue.toPointF());
}



/**
 * @brief updatePoint 更新点位置
 * @param name
 * @param value
 * @return
 */
bool GY_GraphicsRectWidthHeight::updatePoint(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QPointF>()){
        return false;
    }
    //获取鼠标在画板的坐标
    QPointF mousePointF1 = value.value<QPointF>();
    //转为鼠标在屏幕的坐标
    QPointF mousePointF2 = this->mapFromScene(mousePointF1);
    //从map中根据相应标签取出相应数据
    QPointF Position=m_PropertyInfoMap.value("Position").propertyValue.value<QPointF>();//位置变化点
    QPointF pointTran=m_PropertyInfoMap.value("pointTran").propertyValue.value<QPointF>();//形状变化点
    QPointF point1=m_PropertyInfoMap.value("point1").propertyValue.value<QPointF>();//位置变化点
    QPointF point2=m_PropertyInfoMap.value("point2").propertyValue.value<QPointF>();//形状变化点
    QPointF point3=m_PropertyInfoMap.value("point3").propertyValue.value<QPointF>();//位置变化点
    QPointF point4=m_PropertyInfoMap.value("point4").propertyValue.value<QPointF>();//形状变化点
    qreal width=m_PropertyInfoMap.value("Width").propertyValue.value<double>();//矩形宽度
    qreal height=m_PropertyInfoMap.value("Height").propertyValue.value<double>();//矩形高度

    //当位置发生变化时各编辑点的相对位置
    if(name.endsWith("point1")){//拖动point1可使矩形沿水平方向位移(已实现)
        point1.setX(mousePointF2.x());
        m_PropertyInfoMap["point1"].propertyValue=point1;//更新数据后插入map中（下同）

        point2.setX(pointTran.x()-(Position.x()-mousePointF2.x()));
        m_PropertyInfoMap["point2"].propertyValue=point2;

        point3.setX(point1.x()+width/2);
        m_PropertyInfoMap["point3"].propertyValue=point3;

        point4.setX(point1.x()+width/2);
        m_PropertyInfoMap["point4"].propertyValue=point4;

        pointTran.setX(point1.x()+width);
        m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

        Position.setX(mousePointF2.x());
        m_PropertyInfoMap["Position"].propertyValue=Position;
    }
    else if(name.endsWith("point2")){//拖动point2可改变矩形宽度width(已完成)

        point2.setX(mousePointF2.x());
        m_PropertyInfoMap["point2"].propertyValue=point2;

        point3.setX(Position.x()+(pointTran.x()-Position.x())/2);
        m_PropertyInfoMap["point3"].propertyValue=point3;

        point4.setX(Position.x()+(pointTran.x()-Position.x())/2);
        m_PropertyInfoMap["point4"].propertyValue=point4;

        pointTran.setX(mousePointF2.x());
        m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

        width=mousePointF2.x()-Position.x();
        m_PropertyInfoMap["Width"].propertyValue=width;

    }
    else if(name.endsWith("point3")){//拖动point3可改变矩形高度height(已完成)
        point1.setY(Position.y()+(pointTran.y()-Position.y())/2);
//        point1.setY(Position.y()+(pointTran.y()-point2.y()));
        m_PropertyInfoMap["point1"].propertyValue=point1;

        point2.setY(Position.y()+(pointTran.y()-Position.y())/2);
//        point2.setY(Position.y()+(pointTran.y()-point1.y())/2);
        m_PropertyInfoMap["point2"].propertyValue=point2;

        point3.setY(mousePointF2.y());
        m_PropertyInfoMap["point3"].propertyValue=point3;

        pointTran.setY(mousePointF2.y());
        m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

        width=point2.x()-point1.x();
        m_PropertyInfoMap["Width"].propertyValue=width;
        height=pointTran.y()-Position.y();
        m_PropertyInfoMap["Height"].propertyValue=height;
    }
    else if(name.endsWith("point4")){//拖动point4可使矩形沿竖直方向位移(已完成)
        point1.setY(mousePointF2.y()+height/2);
        m_PropertyInfoMap["point1"].propertyValue=point1;

        point2.setY(mousePointF2.y()+height/2);
        m_PropertyInfoMap["point2"].propertyValue=point2;

        point3.setY(mousePointF2.y()+height);
        m_PropertyInfoMap["point3"].propertyValue=point3;

        point4.setY(mousePointF2.y());
        m_PropertyInfoMap["point4"].propertyValue=point4;


        pointTran.setY(mousePointF2.y()+height);
        m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

        Position.setY(mousePointF2.y());
        m_PropertyInfoMap["Position"].propertyValue=Position;
    }
    else if(name.endsWith("pointTran")){//拖动pointTran可使矩形的宽高同时变化(已完成)

        point1.setY(Position.y()+(mousePointF2.y()-Position.y())/2);
        m_PropertyInfoMap["point1"].propertyValue=point1;

//        point2.setX(Position.x()+(mousePointF2.x()-Position.x())/2);
        point2.setX(mousePointF2.x());
//        point2.setY(Position.y()+(pointTran.y()-Position.y())/2);
        point2.setY(point1.y());
        m_PropertyInfoMap["point2"].propertyValue=point2;

//        point3.setX(Position.x()+(mousePointF2.x()-Position.x())/2);
        point3.setX(Position.x()+(mousePointF2.x()-Position.x())/2);
//        point3.setY(Position.y()+(mousePointF2.y()-Position.y())/2);
        point3.setY(mousePointF2.y());
        m_PropertyInfoMap["point3"].propertyValue=point3;

        point4.setX(Position.x()+(mousePointF2.x()-Position.x())/2);
        point4.setY(Position.y());
        m_PropertyInfoMap["point4"].propertyValue=point4;

        pointTran.setX(mousePointF2.x());
        pointTran.setY(mousePointF2.y());
        m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

        width=mousePointF2.x()-Position.x();
        m_PropertyInfoMap["Width"].propertyValue=width;
        height=mousePointF2.y()-Position.y();
        m_PropertyInfoMap["Height"].propertyValue=height;
    }
    else if(name.endsWith("Position")){//拖动Position可使矩形跟随鼠标位置移动
        point1.setX(mousePointF2.x());
        point1.setY(mousePointF2.y()+height/2);
        m_PropertyInfoMap["point1"].propertyValue=point1;

        point2.setX(mousePointF2.x()+width);
        point2.setY(mousePointF2.y()+height/2);
        m_PropertyInfoMap["point2"].propertyValue=point2;

        point3.setX(mousePointF2.x()+width/2);
        point3.setY(mousePointF2.y()+height);
        m_PropertyInfoMap["point3"].propertyValue=point3;

        point4.setX(mousePointF2.x()+width/2);
        point4.setY(mousePointF2.y());
        m_PropertyInfoMap["point4"].propertyValue=point4;

        pointTran.setX(mousePointF2.x()+width);
        pointTran.setY(mousePointF2.y()+height);
        m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

        Position= mousePointF2;
        m_PropertyInfoMap["Position"].propertyValue=Position;
    }
    //当设置长宽时各点坐标与长宽之间的关系
    if(name.endsWith("Width")){
        pointTran.setX(Position.x()+width);
        m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

        point1.setX(Position.x());
        m_PropertyInfoMap["point1"].propertyValue=point1;

        point2.setX(Position.x()+width);
        m_PropertyInfoMap["point2"].propertyValue=point2;

        point3.setX(Position.x()+width/2);
        m_PropertyInfoMap["point3"].propertyValue=point3;

        point4.setX(Position.x()+width/2);
        m_PropertyInfoMap["point4"].propertyValue=point4;

    }
    else if(name.endsWith("Height")){
        pointTran.setY(Position.x()+height);
        m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

        point1.setY(Position.x()+height/2);
        m_PropertyInfoMap["point1"].propertyValue=point1;

        point2.setY(Position.x()+height/2);
        m_PropertyInfoMap["point2"].propertyValue=point2;

        point3.setY(Position.x()+height);
        m_PropertyInfoMap["point3"].propertyValue=point3;

        point4.setY(Position.x());
        m_PropertyInfoMap["point4"].propertyValue=point4;
    }
    /**
     * @brief updatePath
     */
    updatePath(Position,pointTran,QPointF(Position.x()+width,Position.y()),QPointF(Position.x(),Position.y()+height));
    QMap<QVariant,QPointF> editPoints = {{"pointTran",pointTran},
                                         {"point1",point1},{"point2",point2},
                                         {"point3",point3},{"point4",point4}};
    this->setEditPointF(editPoints);
    this->setCenterPointF(Position);
    return true;
}
/**
 * @brief updatePath 根据经过编辑点位置的路径闭合形成矩形
 * @param Position 位置编辑点
 * @param pointTran 形状编辑点
 * @param pointX 上对角点
 * @param pointY 下对角点
 */
void GY_GraphicsRectWidthHeight::updatePath(QPointF Position, QPointF pointTran, QPointF pointX, QPointF pointY)
{
    QPainterPath path=this->path();
    path.clear();
    path.moveTo(Position);
    path.lineTo(pointX);
    path.lineTo(pointTran);
    path.lineTo(pointY);
    path.closeSubpath();
    this->setPath(path);
}
/**
 * @brief initializationPropertyInfo 初始化属性信息
 */
void GY_GraphicsRectWidthHeight::initializationPropertyInfo()
{    
    QPointF Position = QPointF(0,0);//开始的坐标或中心点坐标
    QPointF pointTran = QPointF(1,1);//结束的坐标或径向梯度的焦点坐标
//    qreal width = 100;//中心半径
//    qreal height = 100;//径向梯度的焦点半径
    QVector<qreal> varGradientStyle;
    varGradientStyle<<Position.x()<<Position.y()<<pointTran.x()<<pointTran.y();


    GY_PropertyInfo ObjectName(this);
    ObjectName.propertyName = "ObjectName";
    ObjectName.propertyValue = QString();
    ObjectName.updateType = Update|OrdinaryAttributes;
    ObjectName.propertyType = QStringPropertyType;
    ObjectName.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateObjectName;
    m_PropertyInfoMap.insert("ObjectName",ObjectName);
    m_PropertyInfoMap["ObjectName"].setConnect();

    GY_PropertyInfo IsVisible(this);
    IsVisible.propertyName = "IsVisible";
    IsVisible.propertyValue = true;
    IsVisible.updateType = Update|OrdinaryAttributes;
    IsVisible.propertyType = BoolPropertyType;
    IsVisible.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateIsVisible;
    m_PropertyInfoMap.insert("IsVisible",IsVisible);
    m_PropertyInfoMap["IsVisible"].setConnect();

    GY_PropertyInfo IsOutLined(this);
    IsOutLined.propertyName = "IsOutlined";
    IsOutLined.propertyValue = true;
    IsOutLined.updateType = Update|OrdinaryAttributes;
    IsOutLined.propertyType = BoolPropertyType;
    IsOutLined.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateIsOutLined;
    m_PropertyInfoMap.insert("IsOutlined",IsOutLined);
    m_PropertyInfoMap[IsOutLined.propertyName].setConnect();

    GY_PropertyInfo IsFilled(this);
    IsFilled.propertyName = "IsFilled";
    IsFilled.propertyValue = true;
    IsFilled.updateType = Update|OrdinaryAttributes;
    IsFilled.propertyType = BoolPropertyType;
    IsFilled.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateIsFilled;
    m_PropertyInfoMap.insert("IsFilled",IsFilled);
    m_PropertyInfoMap[IsFilled.propertyName].setConnect();

    GY_PropertyInfo IsAntialiased(this);
    IsAntialiased.propertyName = "IsAntialiased";
    IsAntialiased.propertyValue = false;
    IsAntialiased.updateType = Update|OrdinaryAttributes;
    IsAntialiased.propertyType = BoolPropertyType;
    IsAntialiased.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateIsAntialiased;
    m_PropertyInfoMap.insert("IsAntialiased",IsAntialiased);
    m_PropertyInfoMap[IsAntialiased.propertyName].setConnect();

    GY_PropertyInfo FillAttributes(this);
    FillAttributes.propertyName = "FillAttributes";
    FillAttributes.propertyValue = false;
    FillAttributes.updateType = Update|OrdinaryAttributes;
    FillAttributes.propertyType = BoolPropertyType;
    FillAttributes.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateFillAttributes;
    m_PropertyInfoMap.insert("FillAttributes",FillAttributes);
    m_PropertyInfoMap[FillAttributes.propertyName].setConnect();

    GY_PropertyInfo FillGradient(this);
    FillGradient.propertyName = "FillGradient";
    FillGradient.propertyValue = QVariant::fromValue(varGradientStyle);
    FillGradient.updateType = Update|OrdinaryAttributes;
    FillGradient.propertyType = FillGradientPropertyType;
    FillGradient.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateFillGradient;
    m_PropertyInfoMap.insert("FillGradient",FillGradient);
    m_PropertyInfoMap[FillGradient.propertyName].setConnect();

    GY_PropertyInfo FillColor(this);
    FillColor.propertyName = "FillColor";
    FillColor.propertyValue = QColor(255,255,255);
    FillColor.updateType = Update|OrdinaryAttributes;
    FillColor.propertyType = ColorPropertyType;
    FillColor.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateFillColor;
    m_PropertyInfoMap.insert("FillColor",FillColor);
    m_PropertyInfoMap[FillColor.propertyName].setConnect();

    GY_PropertyInfo FillStyle(this);
    FillStyle.propertyName = "FillStyle";
    FillStyle.propertyValue = false;
    FillStyle.updateType = Update|OrdinaryAttributes;
    FillStyle.propertyType = FillStylePropertyType;
    FillStyle.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateFillStyle;
    m_PropertyInfoMap.insert("FillStyle",FillStyle);
    m_PropertyInfoMap[FillStyle.propertyName].setConnect();

    GY_PropertyInfo FillOpacity(this);
    FillOpacity.propertyName = "FillOpacity";
    FillOpacity.propertyValue = qreal(1.0);
    FillOpacity.updateType = Update|OrdinaryAttributes;
    FillOpacity.propertyType = QrealPropertyType;
    FillOpacity.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateFillOpacity;
    m_PropertyInfoMap.insert("FillOpacity",FillOpacity);
    m_PropertyInfoMap[FillOpacity.propertyName].setConnect();

    GY_PropertyInfo Pattern(this);
    Pattern.propertyName = "Pattern";
    Pattern.propertyValue = 0;
    Pattern.updateType = Update|OrdinaryAttributes;
    Pattern.propertyType = PatternPropertyType;
    Pattern.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updatePattern;
    m_PropertyInfoMap.insert("Pattern",Pattern);
    m_PropertyInfoMap[Pattern.propertyName].setConnect();

    GY_PropertyInfo PenColor(this);
    PenColor.propertyName = "PenColor";
    PenColor.propertyValue = QColor(Qt::white);
    PenColor.updateType = Update|OrdinaryAttributes;
    PenColor.propertyType = ColorPropertyType;
    PenColor.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updatePenColor;
    m_PropertyInfoMap.insert("PenColor",PenColor);
    m_PropertyInfoMap[PenColor.propertyName].setConnect();

    GY_PropertyInfo PenAttributes(this);
    PenAttributes.propertyName = "PenAttributes";
    PenAttributes.propertyValue = false;
    PenAttributes.updateType = Update|OrdinaryAttributes;
    PenAttributes.propertyType = BoolPropertyType;
    PenAttributes.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updatePenAttributes;
    m_PropertyInfoMap.insert("PenAttributes",PenAttributes);
    m_PropertyInfoMap[PenAttributes.propertyName].setConnect();

    GY_PropertyInfo PenOpacity(this);
    PenOpacity.propertyName = "PenOpacity";
    PenOpacity.propertyValue = qreal(1.0);
    PenOpacity.updateType = Update|OrdinaryAttributes;
    PenOpacity.propertyType = QrealPropertyType;
    PenOpacity.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updatePenOpacity;
    m_PropertyInfoMap.insert("PenOpacity",PenOpacity);
    m_PropertyInfoMap[PenOpacity.propertyName].setConnect();

    GY_PropertyInfo LineStyle(this);
    LineStyle.propertyName = "LineStyle";
    QVector<qreal> lineStyle;
    int style = Qt::SquareCap|Qt::BevelJoin|Qt::CustomDashLine;
    lineStyle<<style<<2<<3<<4<<5<<6<<7;//自定义矩形线框样式
    LineStyle.propertyValue = QVariant::fromValue(lineStyle);
    LineStyle.updateType = Update|OrdinaryAttributes;
    LineStyle.propertyType = LineStylePropertyType;
    LineStyle.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateLineStyle;
    m_PropertyInfoMap.insert("LineStyle",LineStyle);
    m_PropertyInfoMap[LineStyle.propertyName].setConnect();

    GY_PropertyInfo positionPropertyInfo(this);
    positionPropertyInfo.propertyName="Position";
    positionPropertyInfo.propertyValue=QPointF(0,0);//
    positionPropertyInfo.updateType = Update|MoveUpdate|PointOfRelative;
    positionPropertyInfo.propertyType = PointPropertyType;
    positionPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updatePoint;
    m_PropertyInfoMap.insert("Position",positionPropertyInfo);
    m_PropertyInfoMap["Position"].setConnect();

    GY_PropertyInfo pointTranPropertyInfo(this);
    pointTranPropertyInfo.propertyName="pointTran";
    pointTranPropertyInfo.propertyValue=QPointF(200,100);//
    pointTranPropertyInfo.updateType = NotUpdate|PointOfRelative;
    pointTranPropertyInfo.propertyType = PointPropertyType;
    pointTranPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updatePoint;
    m_PropertyInfoMap.insert("pointTran",pointTranPropertyInfo);
    m_PropertyInfoMap["pointTran"].setConnect();

    GY_PropertyInfo point1PropertyInfo(this);
    point1PropertyInfo.propertyName="point1";
    point1PropertyInfo.propertyValue=QPointF(0,50);//
    point1PropertyInfo.updateType = NotUpdate|PointOfRelative;
    point1PropertyInfo.propertyType = PointPropertyType;
    point1PropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updatePoint;
    m_PropertyInfoMap.insert("point1",point1PropertyInfo);
    m_PropertyInfoMap["point1"].setConnect();

    GY_PropertyInfo point2PropertyInfo(this);
    point2PropertyInfo.propertyName="point2";
    point2PropertyInfo.propertyValue=QPointF(200,50);//
    point2PropertyInfo.updateType = NotUpdate|PointOfRelative;
    point2PropertyInfo.propertyType = PointPropertyType;
    point2PropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updatePoint;
    m_PropertyInfoMap.insert("point2",point2PropertyInfo);
    m_PropertyInfoMap["point2"].setConnect();

    GY_PropertyInfo point3PropertyInfo(this);
    point3PropertyInfo.propertyName="point3";
    point3PropertyInfo.propertyValue=QPointF(100,100);//
    point3PropertyInfo.updateType = NotUpdate|PointOfRelative;
    point3PropertyInfo.propertyType = PointPropertyType;
    point3PropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updatePoint;
    m_PropertyInfoMap.insert("point3",point3PropertyInfo);
    m_PropertyInfoMap["point3"].setConnect();

    GY_PropertyInfo point4PropertyInfo(this);
    point4PropertyInfo.propertyName="point4";
    point4PropertyInfo.propertyValue=QPointF(100,0);//
    point4PropertyInfo.updateType = NotUpdate|PointOfRelative;
    point4PropertyInfo.propertyType = PointPropertyType;
    point4PropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updatePoint;
    m_PropertyInfoMap.insert("point4",point4PropertyInfo);
    m_PropertyInfoMap["point4"].setConnect();

    GY_PropertyInfo Width(this);
    Width.propertyName = "Width";
    Width.propertyValue = qreal(200);//
    Width.updateType = Update|OrdinaryAttributes;
    Width.propertyType = QrealPropertyType;
    Width.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateWidth;
    m_PropertyInfoMap.insert("Width",Width);
    m_PropertyInfoMap["Width"].setConnect();

    GY_PropertyInfo Height(this);
    Height.propertyName = "Height";
    Height.propertyValue = qreal(100);//
    Height.updateType = Update|OrdinaryAttributes;
    Height.propertyType = QrealPropertyType;
    Height.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsRectWidthHeight::updateHeight;
    m_PropertyInfoMap.insert("Height",Height);
    m_PropertyInfoMap["Height"].setConnect();
}

bool GY_GraphicsRectWidthHeight::updateWidth(const QString &, const QVariant &value)
{
    if(!value.canConvert<qreal>()){
        return false;
    }
    m_PropertyInfoMap["Width"].propertyValue = value;
    QPointF Position=m_PropertyInfoMap.value("Position").propertyValue.value<QPointF>();//位置变化点
    QPointF pointTran=m_PropertyInfoMap.value("pointTran").propertyValue.value<QPointF>();//形状变化点
    QPointF point1=m_PropertyInfoMap.value("point1").propertyValue.value<QPointF>();//横轴位移拖拽点
    QPointF point2=m_PropertyInfoMap.value("point2").propertyValue.value<QPointF>();//宽度变化拖拽点
    QPointF point3=m_PropertyInfoMap.value("point3").propertyValue.value<QPointF>();//高度变化拖拽点
    QPointF point4=m_PropertyInfoMap.value("point4").propertyValue.value<QPointF>();//纵轴位移拖拽点
    qreal width=m_PropertyInfoMap.value("Width").propertyValue.value<double>();//矩形宽度
    qreal height=m_PropertyInfoMap.value("Height").propertyValue.value<double>();//矩形高度
    //当设置宽时各点坐标与长宽之间的关系
    pointTran.setX(Position.x()+width);
    m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

    point1.setX(Position.x());
    m_PropertyInfoMap["point1"].propertyValue=point1;

    point2.setX(Position.x()+width);
    m_PropertyInfoMap["point2"].propertyValue=point2;

    point3.setX(Position.x()+width/2);
    m_PropertyInfoMap["point3"].propertyValue=point3;

    point4.setX(Position.x()+width/2);
    m_PropertyInfoMap["point4"].propertyValue=point4;

    updatePath(Position,pointTran,QPointF(Position.x()+width,Position.y()),QPointF(Position.x(),Position.y()+height));
    QMap<QVariant,QPointF> editPoints = {{"pointTran",pointTran},
                                         {"point1",point1},{"point2",point2},
                                         {"point3",point3},{"point4",point4}};
    this->setEditPointF(editPoints);
    this->setCenterPointF(Position);
    return true;
}

bool GY_GraphicsRectWidthHeight::updateHeight(const QString &, const QVariant &value)
{
    if(!value.canConvert<qreal>()){
        return false;
    }
    m_PropertyInfoMap["Height"].propertyValue = value;
    QPointF Position=m_PropertyInfoMap.value("Position").propertyValue.value<QPointF>();//位置变化点
    QPointF pointTran=m_PropertyInfoMap.value("pointTran").propertyValue.value<QPointF>();//形状变化点
    QPointF point1=m_PropertyInfoMap.value("point1").propertyValue.value<QPointF>();//横轴位移拖拽点
    QPointF point2=m_PropertyInfoMap.value("point2").propertyValue.value<QPointF>();//宽度变化拖拽点
    QPointF point3=m_PropertyInfoMap.value("point3").propertyValue.value<QPointF>();//高度变化拖拽点
    QPointF point4=m_PropertyInfoMap.value("point4").propertyValue.value<QPointF>();//纵轴位移拖拽点
    qreal width=m_PropertyInfoMap.value("Width").propertyValue.value<double>();//矩形宽度
    qreal height=m_PropertyInfoMap.value("Height").propertyValue.value<double>();//矩形高度
    //当设置高时各点坐标与长宽之间的关系
    pointTran.setY(Position.x()+height);
    m_PropertyInfoMap["pointTran"].propertyValue=pointTran;

    point1.setY(Position.x()+height/2);
    m_PropertyInfoMap["point1"].propertyValue=point1;

    point2.setY(Position.x()+height/2);
    m_PropertyInfoMap["point2"].propertyValue=point2;

    point3.setY(Position.x()+height);
    m_PropertyInfoMap["point3"].propertyValue=point3;

    point4.setY(Position.x());
    m_PropertyInfoMap["point4"].propertyValue=point4;

    updatePath(Position,pointTran,QPointF(Position.x()+width,Position.y()),QPointF(Position.x(),Position.y()+height));
    QMap<QVariant,QPointF> editPoints = {{"pointTran",pointTran},
                                         {"point1",point1},{"point2",point2},
                                         {"point3",point3},{"point4",point4}};
    this->setEditPointF(editPoints);
    this->setCenterPointF(Position);
    return true;
}





